package com.muye.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.muye.dianli.R;
import com.muye.field.ContactData;

/**
 * 联系我们适配器
 * 
 * @author TangChao
 *
 */
public class ContactAdapter extends BaseAdapter
{
	private Context context;
	
	private List<ContactData> arrayList;
	
	public ContactAdapter(Context context, List<ContactData> arrayList)
	{
		super();
		this.context = context;
		this.arrayList = arrayList;
	}
	
	@Override
	public int getCount()
	{
		if (arrayList != null)
		{
			return arrayList.size();
		}
		return 0;
	}
	
	@Override
	public ContactData getItem(int position)
	{
		if (arrayList != null)
		{
			return arrayList.get(position);
		}
		return null;
	}
	
	@Override
	public long getItemId(int position)
	{
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		final ViewHolder viewHolder;
		if (convertView == null)
		{
			convertView = LayoutInflater.from(context).inflate(R.layout.contact_adapter_layout, null);
			viewHolder = new ViewHolder();
			viewHolder.phone = (TextView) convertView.findViewById(R.id.contact_adapter_layout_phone_text);
			viewHolder.address = (TextView) convertView.findViewById(R.id.contact_adapter_layout_address_text);
			viewHolder.describe = (TextView) convertView.findViewById(R.id.contact_adapter_layout_describe_text);
			convertView.setTag(viewHolder);
		}
		else
		{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if (viewHolder != null)
		{
			ContactData item = arrayList.get(position);
			viewHolder.phone.setText("电话: " + item.phone);
			viewHolder.address.setText("地址: " + item.address);
			viewHolder.describe.setText("描述: " + item.desc);
		}
		return convertView;
	}
	
	private class ViewHolder
	{
		TextView phone;
		
		TextView address;
		
		TextView describe;
	}
	
}
